package yuan.deng.service.impl;

import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;
import yuan.deng.mapper.UserMapper;
import yuan.deng.pojo.User;
import yuan.deng.service.UserService;

import java.io.IOException;
import java.io.InputStream;
import java.util.List;

public class UserServiceImpl implements UserService {
    private static UserMapper userMapper=null;

    static {
        InputStream is = null;
        SqlSession sqlSession =null;
        try {
            is = Resources.getResourceAsStream("Config.xml");
            SqlSessionFactory sqlSessionFactory=new  SqlSessionFactoryBuilder().build(is);
            sqlSession = sqlSessionFactory.openSession(true);
            userMapper=sqlSession.getMapper(UserMapper.class);
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
    @Override
    public List<User> finAll() {
        List<User> list = userMapper.finAll();
        return list;
    }

    @Override
    public User findById(int i) {
        User user=userMapper.findById(i);
        return null;
    }

    @Override
    public int addUser(User user) {
        return userMapper.addUser(user);
    }

    @Override
    public User findByUser(User u) {
        return userMapper.findByUser(u);
    }
}
